package com.zhaopin.theswordreferstooffer;

/**
 * @author yin.peide
 * @date 2021-06-21 15:26
 * 面试题31：连续子数组的最大和 ,还有动态规划，有时间再看//TODO
 */
public class Offer31 {

    public static void main(String[] args) {

        int[] attr = {1, -2, 3, 10, -4, 7, 2, -5};
        System.out.println(getIntAttr(attr));


    }

    public static int getIntAttr(int[] intAttr) {


        int addVal = 0;
        //缓存最大值
        int max = 0;

        for (int element : intAttr) {
            if (addVal <= 0) {
                addVal = element;
            } else {
                addVal += element;
            }

            max = Math.max(max, addVal);


        }
        return max;
    }

}
